home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 1995 May / PC Answers CD-ROM 7 (Future Publishing) (May 1995).iso / vbits / code / zuck / changepr.frm (.txt) next >
Encoding:
Visual Basic Form  |  1994-10-06  |  3.3 KB  |  106 lines

  1. VERSION 2.00
  2. Begin Form ChangePrinter 
  3.    Caption         =   "Changing the Default Printer"
  4.    ClientHeight    =   2370
  5.    ClientLeft      =   3330
  6.    ClientTop       =   4155
  7.    ClientWidth     =   4470
  8.    Height          =   2775
  9.    Left            =   3270
  10.    LinkTopic       =   "Form2"
  11.    ScaleHeight     =   2370
  12.    ScaleWidth      =   4470
  13.    Top             =   3810
  14.    Width           =   4590
  15.    Begin CommandButton Command2 
  16.       Caption         =   "PrintForm"
  17.       Height          =   495
  18.       Left            =   300
  19.       TabIndex        =   3
  20.       Top             =   1500
  21.       Width           =   1335
  22.    End
  23.    Begin ComboBox Combo1 
  24.       Height          =   300
  25.       Left            =   120
  26.       Style           =   2  'Dropdown List
  27.       TabIndex        =   1
  28.       Top             =   540
  29.       Width           =   4155
  30.    End
  31.    Begin CommandButton Command1 
  32.       Caption         =   "Ok"
  33.       Height          =   495
  34.       Left            =   2880
  35.       TabIndex        =   0
  36.       Top             =   1500
  37.       Width           =   1395
  38.    End
  39.    Begin Label Label1 
  40.       Caption         =   "Default Printer"
  41.       Height          =   255
  42.       Left            =   120
  43.       TabIndex        =   2
  44.       Top             =   180
  45.       Width           =   2955
  46.    End
  47. ' ------------------------------------------------------------------------
  48. '     changepr.frm -- Top 9 API Tricks
  49. '                       Copyright (C) 1993 Desaware
  50. '  You have a royalty-free right to use, modify, reproduce and distribute
  51. '  this file (and/or any modified version) in any way you find useful,
  52. '  provided that you agree that Desaware has no
  53. '  warranty, obligation or liability for its contents.
  54. ' ------------------------------------------------------------------------
  55. Option Explicit
  56. Sub Combo1_Click ()
  57.     Dim di%, dl&
  58.     Dim newpr$
  59.     newpr$ = Combo1.Text
  60.     If Len(newpr$) > 0 Then
  61.         di% = WriteProfileString("windows", "device", newpr$)
  62.         ' Notify all applications that printer has changed
  63.         dl& = SendMessageByString(HWND_BROADCAST, WM_WININICHANGE, 0, "windows")
  64.     End If
  65. End Sub
  66. Sub Command1_Click ()
  67.     Unload Me
  68. End Sub
  69. Sub Command2_Click ()
  70.     Me.PrintForm
  71. End Sub
  72. Sub Form_Load ()
  73.     Dim pr$
  74.     Dim di%, x%
  75.     Dim defpr$
  76.     Dim thispr$
  77.     pr$ = String$(2048, 0)  ' Initialize the string
  78.     defpr$ = String$(256, 0)
  79.     di% = GetProfileString("windows", "device", "", defpr$, 2047)
  80.     defpr$ = NullTermToVBString$(defpr$)
  81.     ' Note use of byval to pass null
  82.     di% = GetProfileString("devices", ByVal 0&, "", pr$, 2047)
  83.     x% = 0
  84.     Do
  85.         thispr$ = ParseAnyString(pr$, x%, Chr$(0))
  86.         If thispr$ <> "" Then
  87.             Combo1.AddItem GetRealPr$(thispr$)
  88.         End If
  89.         x% = x% + 1
  90.     Loop While thispr$ <> ""
  91.     ' Select the current one
  92.     For x% = 0 To Combo1.ListCount - 1
  93.         If UCase$(Combo1.List(x%)) = UCase$(defpr$) Then
  94.             Combo1.ListIndex = x%
  95.             Exit For
  96.         End If
  97.     Next x%
  98. End Sub
  99. Function GetRealPr$ (thispr$)
  100.     Dim newpr$
  101.     Dim di%
  102.     newpr$ = String$(255, 0)
  103.     di% = GetProfileString("devices", thispr$, "", newpr$, 254)
  104.     GetRealPr$ = thispr$ & "," & NullTermToVBString(newpr$)
  105. End Function
  106.